import { StoreOptions } from "vuex";
import AuthorityState from 'declares/store/authority-state'
import { menu } from "@/declare/system/module";

/**
 * 用户状态管理
 */
 const authority: StoreOptions<AuthorityState> = {
    state: {
        loadMenuTime: 0
        , loadMenuKey: ''
        , loadMenus: []
    }
    , mutations: {
        /**
         * 加载权限菜单
         * @param state 
         * @param menus 菜单  
         */
        LOAD_MENU(state, menus: Array<menu>) {
       
            // TODO 当前的token
            state.loadMenuTime = Date.now();
            state.loadMenuKey = '';
            state.loadMenus = menus;
        }
    }
    , actions: {

    }
    , getters: {
        /**
         * 判断是否需要重新构建菜单
         * @returns 
         */
        needToReloadMenus(state): boolean {
            // TODO 临时写法，等token加入进去后，用token状态即loadMenuKey来验证是否需要重新加载
            return state.loadMenus.length != 0;
        }
        /**
         * 获取当前加载的菜单
         */
        , menuArray(state) {
            return state.loadMenus;
        }
    }
}

export default authority;